//
//  ConlectionViewController.m
//  UI12豆瓣大项目
//
//  Created by 李奇 on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ConlectionViewController.h"
#import "FilmViewController.h"
#import "NineViewController.h"
#import "ItemNineViewController.h"

@interface ConlectionViewController ()
@property (nonatomic,retain) FilmViewController *filmVC;
//@property (nonatomic,retain) NineViewController *nineVC;
@property (nonatomic,retain) ItemNineViewController *ItemVC;
@property (nonatomic,retain) UIImage *rightBarI;
@property (nonatomic,retain) UIButton *changeVC;
@end

@implementation ConlectionViewController

- (void)dealloc
{
    [_filmVC release];
//    [_nineVC release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"电影";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav"] forBarMetrics:UIBarMetricsDefault];
    
//    self.nineVC = [[NineViewController alloc] init];
//    [self addChildViewController:self.nineVC];
//    [self.view addSubview:self.nineVC.view];
//    [_nineVC release];
    
    self.ItemVC = [[ItemNineViewController alloc] init];
    [self addChildViewController:self.ItemVC];
    [self.view addSubview:self.ItemVC.view];
    [_ItemVC release];
    
    self.filmVC = [[FilmViewController alloc] init];
    [self addChildViewController:self.filmVC];
    [self.view addSubview:self.filmVC.view];
    [_filmVC release];
    
    
    self.rightBarI = [UIImage imageNamed:@"btn_nav_collection@2x"];
    self.rightBarI = [self.rightBarI imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.changeVC = [UIButton buttonWithType:UIButtonTypeCustom];
    self.changeVC.selected = NO;
    [self.changeVC addTarget:self action:@selector(changeVC:) forControlEvents:UIControlEventTouchUpInside];
    [self.changeVC setImage:self.rightBarI forState:UIControlStateNormal];
    self.changeVC.frame = CGRectMake(0, 0, 40, 40);
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:self.changeVC] autorelease];
}




-(void)changeVC:(UIButton *)button{
    if (button.selected == YES) {
        UIImage *rightBarI = [UIImage imageNamed:@"btn_nav_collection@2x"];
        //取消渲染
        rightBarI = [rightBarI imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [self.changeVC setImage:rightBarI forState:UIControlStateNormal];
        //切换view
        [UIView transitionFromView:self.ItemVC.view toView:self.filmVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
        }];
    }
    else{

        UIImage *rightBarI = [UIImage imageNamed:@"btn_nav_list@2x"];
        //取消渲染
        rightBarI = [rightBarI imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [self.changeVC setImage:rightBarI forState:UIControlStateNormal];
        [UIView transitionFromView:self.filmVC.view toView:self.ItemVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
        }];
    }
    button.selected = !button.selected;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
